<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取结果数据的所有行到一个数组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.oci-fetch-all" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_fetch_all</h1>
  <p class="verinfo">(PHP 5, PHP 7, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_fetch_all</span> &mdash; <span class="dc-title">获取结果数据的所有行到一个数组</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.oci-fetch-all-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_fetch_all</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$statement</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$output</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$skip</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$maxrows</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>
  ]]] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>oci_fetch_all()</strong></span>
   从一个结果中获取所有的行到一个用户定义的数组。<span class="function"><strong>oci_fetch_all()</strong></span>
   返回获取的行数，出错则返回 <strong><code>FALSE</code></strong>。<code class="parameter">skip</code>
   是从结果中获取数据时，最开始忽略的行数（默认值是
   0，即从第一行开始）。<code class="parameter">maxrows</code>
   是要读取的行数，从第 <code class="parameter">skip</code>
   行开始（默认值是 -1，即所有行）。
  </p>
  <p class="para">
   <code class="parameter">flags</code> 参数可以是下列值的任意组合：
   <ul class="simplelist">
    <li class="member">
     <strong><code>OCI_FETCHSTATEMENT_BY_ROW</code></strong>
    </li>
    <li class="member">
     <strong><code>OCI_FETCHSTATEMENT_BY_COLUMN</code></strong>（默认值）
    </li>
    <li class="member">
     <strong><code>OCI_NUM</code></strong>
    </li>
    <li class="member">
     <strong><code>OCI_ASSOC</code></strong>
    </li>
   </ul>
  </p>
  <p class="para">
   <div class="example" id="example-2414">
    <p><strong>Example #1 <span class="function"><strong>oci_fetch_all()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;oci_fetch_all&nbsp;example&nbsp;mbritton&nbsp;at&nbsp;verinet&nbsp;dot&nbsp;com&nbsp;(990624)&nbsp;*/<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"scott"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"tiger"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;emp"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$nrows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_fetch_all</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$results</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$nrows&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;table&nbsp;border=\"1\"&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;tr&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$results&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;th&gt;</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">&lt;/th&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/tr&gt;\n"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$nrows</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;tr&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$results&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;td&gt;</span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]</span><span style="color: #DD0000">&lt;/td&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/tr&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/table&gt;\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"No&nbsp;data&nbsp;found&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />}<br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$nrows</span><span style="color: #DD0000">&nbsp;Records&nbsp;Selected&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <span class="function"><strong>oci_fetch_all()</strong></span> 如果出错则返回 <strong><code>FALSE</code></strong>。
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    在 PHP 5.0.0 之前的版本必须使用 <span class="function"><a href="ocifetchstatement.html" class="function">ocifetchstatement()</a></span>
    替代本函数。该函数名仍然可用，为向下兼容作为
    <span class="function"><strong>oci_fetch_all()</strong></span> 的别名。不过其已被废弃，不推荐使用。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-fetch-all-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">statement</code></dt>

     <dd>

       <p class="para">有效的 OCI8 报表标识符
由 <span class="function"><a href="oci_parse.html" class="function">oci_parse()</a></span> 创建，被 <span class="function"><a href="oci_execute.html" class="function">oci_execute()</a></span>
或 <em>REF CURSOR</em> statement 标识执行。</p>
     </dd>

    
    
     <dt>
<code class="parameter">output</code></dt>

     <dd>

      <p class="para">
       The variable to contain the returned rows.
      </p>
      <p class="para">
        LOB columns are returned as strings, where Oracle supports
        conversion.
      </p>
      <p class="para">
        See <span class="function"><a href="oci_fetch_array.html" class="function">oci_fetch_array()</a></span> for more information
        on how data and types are fetched.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">skip</code></dt>

     <dd>

      <p class="para">
       The number of initial rows to discard when fetching the
       result. The default value is 0, so the first row onwards is
       returned.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">maxrows</code></dt>

     <dd>

      <p class="para">
       The number of rows to return.  The default is -1 meaning return
       all the rows from <code class="parameter">skip</code> + 1 onwards.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       Parameter <code class="parameter">flags</code> indicates the array
       structure and whether associative arrays should be used.
       <table class="doctable table">
        <caption><strong><span class="function"><strong>oci_fetch_all()</strong></span> Array Structure Modes</strong></caption>
        
         <thead>
          <tr>
           <th>Constant</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code>OCI_FETCHSTATEMENT_BY_ROW</code></strong></td>
           <td>The outer array will contain one sub-array per query
           row.</td>
          </tr>

          <tr>
           <td><strong><code>OCI_FETCHSTATEMENT_BY_COLUMN</code></strong></td>
           <td>The outer array will contain one sub-array per query
           column. This is the default.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
        Arrays can be indexed by column heading or numerically.
       <table class="doctable table">
        <caption><strong><span class="function"><strong>oci_fetch_all()</strong></span> Array Index Modes</strong></caption>
        
         <thead>
          <tr>
           <th>Constant</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code>OCI_NUM</code></strong></td>
           <td>Numeric indexes are used for each column&#039;s array.</td>
          </tr>

          <tr>
           <td><strong><code>OCI_ASSOC</code></strong></td>
           <td>Associative indexes are used for each column&#039;s
           array. This is the default.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       Use the addition operator &quot;+&quot; to choose a combination
       of array structure and index modes.
      </p>
      <p class="para">
       Oracle&#039;s default, non-case sensitive column names will have
       uppercase array keys.  Case-sensitive column names will have
       array keys using the exact column case.
       Use <span class="function"><a href="var_dump.html" class="function">var_dump()</a></span>
       on <code class="parameter">output</code> to verify the appropriate case
       to use for each query.
      </p>
      <p class="para">
        Queries that have more than one column with the same name
        should use column aliases.  Otherwise only one of the columns
        will appear in an associative array.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-fetch-all-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the number of rows in <code class="parameter">output</code>, which
   may be 0 or more,  或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.oci-fetch-all-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2415">
    <p><strong>Example #2 <span class="function"><strong>oci_fetch_all()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$e&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;POSTAL_CODE,&nbsp;CITY&nbsp;FROM&nbsp;locations&nbsp;WHERE&nbsp;ROWNUM&nbsp;&lt;&nbsp;3'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$nrows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_fetch_all</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$nrows</span><span style="color: #DD0000">&nbsp;rows&nbsp;fetched&lt;br&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;var_dump&nbsp;output&nbsp;is:<br />//&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;rows&nbsp;fetched<br />//&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["POSTAL_CODE"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"00989x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"10934x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["CITY"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(4)&nbsp;"Roma"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"Venice"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />//&nbsp;Pretty-print&nbsp;the&nbsp;results<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"&lt;table&nbsp;border='1'&gt;\n"</span><span style="color: #007700">;<br />foreach&nbsp;(</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$col</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;tr&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$col&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$item</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;"</span><span style="color: #007700">.(</span><span style="color: #0000BB">$item&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">null&nbsp;</span><span style="color: #007700">?&nbsp;</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">)&nbsp;:&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">).</span><span style="color: #DD0000">"&lt;/td&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;/tr&gt;\n"</span><span style="color: #007700">;<br />}<br />echo&nbsp;</span><span style="color: #DD0000">"&lt;/table&gt;\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2416">
    <p><strong>Example #3 <span class="function"><strong>oci_fetch_all()</strong></span> example with <strong><code>OCI_FETCHSTATEMENT_BY_ROW</code></strong></strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$e&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;POSTAL_CODE,&nbsp;CITY&nbsp;FROM&nbsp;locations&nbsp;WHERE&nbsp;ROWNUM&nbsp;&lt;&nbsp;3'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$nrows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_fetch_all</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">OCI_FETCHSTATEMENT_BY_ROW</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$nrows</span><span style="color: #DD0000">&nbsp;rows&nbsp;fetched&lt;br&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output&nbsp;is:<br />//&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;rows&nbsp;fetched<br />//&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["POSTAL_CODE"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"00989x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["CITY"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(4)&nbsp;"Roma"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["POSTAL_CODE"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"10934x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["CITY"]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"Venice"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2417">
    <p><strong>Example #4 <span class="function"><strong>oci_fetch_all()</strong></span> with <strong><code>OCI_NUM</code></strong></strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$e&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;POSTAL_CODE,&nbsp;CITY&nbsp;FROM&nbsp;locations&nbsp;WHERE&nbsp;ROWNUM&nbsp;&lt;&nbsp;3'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$nrows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_fetch_all</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">OCI_FETCHSTATEMENT_BY_ROW&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">OCI_NUM</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$nrows</span><span style="color: #DD0000">&nbsp;rows&nbsp;fetched&lt;br&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output&nbsp;is:<br />//&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;rows&nbsp;fetched<br />//&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"00989x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(4)&nbsp;"Roma"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(2)&nbsp;{<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"10934x"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1]=&gt;<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string(6)&nbsp;"Venice"<br />//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />//&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.oci-fetch-all-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
     Using <code class="parameter">skip</code> is very inefficient.  All the
     rows to be skipped are included in the result set that is
     returned from the database to PHP.  They are then discarded.  It
     is more efficient to use SQL to restrict the offset and range of
     rows in the query.  See <span class="function"><a href="oci_fetch_array.html" class="function">oci_fetch_array()</a></span> for
     an example.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Queries that return a large number of rows can be more memory
    efficient if a single-row fetching function
    like <span class="function"><a href="oci_fetch_array.html" class="function">oci_fetch_array()</a></span> is used.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
查询返回巨大数量的数据行时，通过增大
<a href="oci8.configuration.html#ini.oci8.default-prefetch" class="link">oci8.default_prefetch</a>
值或使用 <span class="function"><a href="oci_set_prefetch.html" class="function">oci_set_prefetch()</a></span> 可显著提高性能。</p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    In PHP versions before 5.0.0 you must
    use <span class="function"><a href="ocifetchstatement.html" class="function">ocifetchstatement()</a></span>
    instead. 在当前版本中，旧的函数名还可以被使用，但已经被废弃并不建议使用。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.oci-fetch-all-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="oci_fetch.html" class="function" rel="rdfs-seeAlso">oci_fetch()</a> - Fetches the next row into result-buffer</span></li>
    <li class="member"><span class="function"><a href="oci_fetch_array.html" class="function" rel="rdfs-seeAlso">oci_fetch_array()</a> - Returns the next row from a query as an associative or numeric array</span></li>
    <li class="member"><span class="function"><a href="oci_fetch_assoc.html" class="function" rel="rdfs-seeAlso">oci_fetch_assoc()</a> - Returns the next row from a query as an associative array</span></li>
    <li class="member"><span class="function"><a href="oci_fetch_object.html" class="function" rel="rdfs-seeAlso">oci_fetch_object()</a> - Returns the next row from a query as an object</span></li>
    <li class="member"><span class="function"><a href="oci_fetch_row.html" class="function" rel="rdfs-seeAlso">oci_fetch_row()</a> - Returns the next row from a query as a numeric array</span></li>
    <li class="member"><span class="function"><a href="oci_set_prefetch.html" class="function" rel="rdfs-seeAlso">oci_set_prefetch()</a> - 设置预提取行数</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>